package Sort2017;

/**
 * 选择排序
 * Created by 雷文康 on 2017/12/25.
 */
public class SelectSort {
    public static void main(String[] args) {
        int[] array = {3,8,4,6,7,2,5,9,1};
        selectSort(array);
        for (int i = 0; i < array.length; i++){
            System.out.print(array[i]);
        }
    }
    public static void selectSort(int[] array) {
        if (array == null || array.length == 0) {
            return;
        }
        for (int i = 0; i < array.length; i++) {
            int min = i;
            for (int j = i + 1; j < array.length; j++) {
                if (array[j] < array[min]){
                    min = j;
                }
            }
            if (min != i) {
                int temp = array[i];
                array[i] = array[min];
                array[min] = temp;
            }
        }
    }
}
